﻿/*
{
"状态":1,
"名称":"获取-用户部门信息",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"获取-用户部门信息",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : "type取值 in或not in"}
]
}
*/

declare @sql varchar(max)
declare @where varchar(max)
declare @type varchar(max)
declare @company_key int
declare @department_key int

set @company_key = '{company_key}'
set @department_key = '{department_key}'
set @type = '{type}'
set @where = ''
set @where += ' and company_key ='+convert(varchar,@company_key)
set @where += ' and user_key '+ @type +' (select user_key from y_department_user where department_key = '+convert(varchar,@department_key)+')'

set @sql = 'select user_key,user_name from y_user where 1=1 {where} '
set @sql =replace(@sql,'{where}',@where)

exec(@sql)
